<template>
  <div class="doctorApplyList padding_20">
    <el-input v-model="param.searchCondition"
              placeholder="医生/联系方式"
              class="w-200"
              clearable
              @clear="handleQuery" />
    <el-button type="primary"
               @click="handleQuery">查 询</el-button>
    <Table :columns="tableCol"
           :data="tableData"
           border
           stripe
           class="mt-20">
      <template slot-scope="{row,index}"
                slot="action">
        <span @click="handleReject(row)"
              v-if="row.passStatus==0">驳回</span>
        <span @click="handlePass(row)"
              v-if="row.passStatus==0">通过</span>
        <span @click="handleView(row)">详细</span>
      </template>
    </Table>
    <page @getList="_getList"
          :pageTotal="pageTotal"
          ref="page"></page>
    <doctorApplyView ref="doctorApplyView"></doctorApplyView>
  </div>
</template>

<script>

  import Page from '@/base/page/page'
  import { mapGetters } from 'vuex'
  import { doctor } from '@/api/codeName'
  import DoctorApplyView from '@/components/page/doctor/doctorApplyView'
  export default {
    name: "doctorApplyList",
    data () {
      return {
        tableCol: [
          {
            type: 'index2',
            title: '',
            width: 60,
            render: (h, params) => {
              return h('span', params.index + (this.page.pageIndex) * this.page.pageSize + 1);
            }
          },
          {
            title: '工作证',
            key: 'certiUrl',
            // width: 95,
            render: (h, params) => {
              return h('div', [
                h('img', {
                  attrs: {
                    src: params.row.certiUrl,
                    preview: 'doctorApplyList'
                  },
                  style: {
                    width: '50px',
                    height: '50px',
                    margin: '10px'
                  }
                }),
              ]);
            }
          },
          {
            title: '执业证',
            key: 'qualiUrl',
            // width: 95,
            render: (h, params) => {
              return h('div', [
                h('img', {
                  attrs: {
                    src: params.row.qualiUrl,
                    preview: 'doctorApplyList'
                  },
                  style: {
                    width: '50px',
                    height: '50px',
                    margin: '10px'
                  }
                }),
              ]);
            }
          },
          {
            title: '医生',
            key: 'nickName',
            render: (h, params) => {
              return h('span', params.row.doctorDto.nickName);
            }
          },
          {
            title: '联系方式',
            key: 'loginName',
            render: (h, params) => {
              return h('span', params.row.doctorDto.loginName);
            }
          },
          {
            title: '科室',
            key: 'departmentName',
            render: (h, params) => {
              return h('span', params.row.doctorDto.departmentName);
            }
          },
          {
            title: '职称',
            key: 'doctorTitle',
            render: (h, params) => {
              return h('span', params.row.doctorTitle);
            }
          },
          {
            title: '医院',
            key: 'hospitalName',
            render: (h, params) => {
              return h('span', params.row.doctorDto.hospitalName);
            }
          },
          {
            title: '状态',
            key: 'passStatus',
            render: (h, params) => {
              let tmp = '';
              doctor.doctorWithdrawals.status.forEach(obj => {
                if (params.row.passStatus == obj.code) {
                  tmp = obj.name
                }
              });
              return h('span', tmp);
            }
          },
          {
            title: '申请时间',
            key: 'createTime',
            width: 150,
            render: (h, params) => {
              return h('span',
                this.commonFunction.timestampFormat(new Date(params.row.createTime), 'yyyy-MM-dd hh:mm'));
            }
          },
          {
            title: '操作',
            slot: 'action',
            align: 'center'
          }
        ],
        tableData: [],
        pageTotal: 0,       //总条数
        wdStudioTypeList: [],
        hospitalList: [],
        loading: false,
        param: {
          searchCondition: ''
        }
      }
    },
    mounted () {
      if (this.params.doctorApplyList) {
        this.param = this.params.doctorApplyList
      } else {
        this.$store.commit('SET_PARAMS', { doctorApplyList: this.param })
      }
      this._getList()
    },
    methods: {
      handleReject (row) {
        this.$Modal.confirm({
          title: '确认',
          content: '<p>您确认驳回该申请？</p>',
          onOk: () => {
            this.ajax({
              type: this.api.doctorApplyReject.type,
              url: this.api.doctorApplyReject.url,
              isDel: true,
              data: {
                id: row.id,
              },
              success: (data) => {
                this.$Message.success('驳回成功！');
                this._getList()
              },
              error: (data) => {
                this.$Message.error(data.message);
              }
            })
          },
          onCancel: () => { }
        });
      },
      handlePass (row) {
        this.$Modal.confirm({
          title: '确认',
          content: '<p>您确认通过该申请？</p>',
          onOk: () => {
            this.ajax({
              type: this.api.doctorApplyPass.type,
              url: this.api.doctorApplyPass.url,
              isDel: true,
              data: {
                id: row.id,
              },
              success: (data) => {
                this.$Message.success('通过成功！');
                this._getList()
              },
              error: (data) => {
                this.$Message.error(data.message);
              }
            })
          },
          onCancel: () => { }
        });
      },
      handleView (row) {
        this.$refs.doctorApplyView.openView(row)
      },
      handleQuery () {
        this.page.pageIndex=0
        this._getList()
      },
      _getList () {
        this.ajax({
          type: this.api.doctorApplyList.type,
          url: this.api.doctorApplyList.url,
          data: Object.assign({}, this.page, this.param),
          success: (data) => {
            this.tableData = data.object
            this.pageTotal = data.totalNum
            this.$previewRefresh()
          },
          error: (data) => {
            this.$Message.error(data.message);
          }
        })
      }
    },
    computed: {
      ...mapGetters([
        'page',
        'params'
      ])
    },
    components: {
      Page,
      DoctorApplyView
    }
  }
</script>

<style lang="scss" type="text/scss" rel="stylesheet/scss">
  .doctorApplyList {
  }
</style>
